﻿using com.fmtx.IDal;
using fmtx.Framework.DALFactory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using com.fmtx.Model;
using System.Collections;

namespace website.Areas.Tool.Controllers
{
    public class PictureController : BaseController
    {
        //
        // GET: /Tool/Picture/
        private IPictureType pictureType = DataAccess<IPictureType>.GetObject();
        private IPicture picture = DataAccess<IPicture>.GetObject();
        private IKeyWord keyword = DataAccess<IKeyWord>.GetObject();

        /// <summary>
        /// 打开相册编辑窗口
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [IsLoginBox]
        public ActionResult OpenEditTypeBox(int id)
        {
            var model = pictureType.Get(id);
            if (model.Uid != userInfo.Uid)
            {
                return Redirect("/login/OpenBoxLogin");
            }
            ViewBag.Keyword = keyword.QueryHost(5,Target.PICTRUE);
            return PartialView(model);
        }

        /// <summary>
        /// 保存相册信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        [ApiIsLogin]
        public ActionResult EditType(PictureType model)
        {
            if (ModelState.IsValid)
            {
                var o = pictureType.Get(model.Id);
                model.Uid = o.Uid;
                if (model.Uid != userInfo.Uid)
                {
                    return Redirect("/login");
                }
                model.FrontCover = o.FrontCover;
                model.KeyWord = StaticCs.SaveKeyWord(model.KeyWord,Target.PICTRUE);
                pictureType.Update(model);
                return Redirect("/" + model.Uid + "/Photo/detail/" + model.Id);
            }
            return Error();
        }

    }
}
